package com.test.day03.method01;

import java.io.File;

/**
 * @program: File判断功能的方法
 * @author: luhd
 * @create: 2021-08-01
 */
public class Demo04File {
    public static void main(String[] args) {
        show01(); // 判断文件夹/文件是否存在
        show02(); // 判断路径是以文件结尾还是以文件夹结尾
    }
    private static void show01(){
        File f1 = new File("D:\\myProject\\javaTest");
        System.out.println(f1.exists());

        File f2 = new File("D:\\myProject\\javaTest\\a.txt");
        System.out.println(f2.exists());

        File f3 = new File("javaTest.iml");
        System.out.println(f3.exists());
    }
    private static void show02(){
        File f1 = new File("D:\\myProject\\javaTest\\a.txt");
        if(f1.exists()){
            System.out.println(f1.isDirectory());
            System.out.println(f1.isFile());
        }

        File f2 = new File("D:\\myProject\\javaTest");
        if(f2.exists()){
            System.out.println(f2.isDirectory());
            System.out.println(f2.isFile());
        }

        File f3 = new File("D:\\myProject\\javaTest\\javaTest.iml");
        if(f3.exists()){
            System.out.println(f3.isDirectory());
            System.out.println(f3.isFile());
        }
    }
}
